package com.he.hsdyc.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.util.Collection;
import java.util.Date;

/**
 * @Author :
 * @Date : Created in 10:54 2017/10/11
 * @Modified By : NONE
 */

@Entity
@Table(name="admin_user")
@Data                                                   //所有属性生成getter/setter方法
@NoArgsConstructor                                      //生成无参构造函数
@AllArgsConstructor                                     //生成所有参数构造函数
public class User2 implements UserDetails {                                     //上述注解暂未做测试
    public final static int ENABLE = 1;
    public final static int DISABLE = 2;
    public final static int DELETE = 3;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return null;
    }


    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
//    @Id
//    @GeneratedValue(generator = "uuid")
//    @GenericGenerator(name = "uuid",strategy = "uuid")
    private String id;
//    @Column(name = "user_name")
    private String userName;
    private String gender;
    private String mobile;
   // @Column(name = "real_name") 无需写column，数据库自动映射为real_name;
    private String realName;

    //TODO: 2017/10/11 @JSONField @ApiModelProperty  导入失败
//    @ApiModelProperty(hidden = true)
//    @JSONField(serialize = false)
//    @Column(name = "user_password")
    private String password;

//    @JsonSubTypes.Type(type = "yes_no")
    private Boolean allowDelete = true;
    //@Column(insertable = false)表示不插入值
    private Integer state = User2.ENABLE;


    //userInfo新增属性
    private String        salt;//加密密码的盐
//    @ManyToMany(fetch= FetchType.EAGER)//立即从数据库中进行加载数据;也可以用lazy属性进行懒加载
//    @JoinTable(name = "SysUserRole", joinColumns = { @JoinColumn(name = "uid") }, inverseJoinColumns ={@JoinColumn(name = "roleId") })
//    private List<SysRole> roleList;// 一个用户具有多个角色
//    public String getCredentialsSalt(){
//        return this.userName+this.salt;
//    }
    //重新对盐重新进行了定义，用户名+salt，这样就更加不容易被破解

//    @JSONField(format = "yyyy/MM/dd")
//    @Column(updatable = false)
    private Date createTime;
}
